package com.yunhai.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunhai.common.dto.GlobalException;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.utils.ObjectUtil;
import com.yunhai.common.utils.ReflectionCopy;
import com.yunhai.device.mapper.OrrMaterialInterruptSummaryMapper;
import com.yunhai.device.service.OrrMaterialInterruptSummaryService;
import com.yunhai.model.entity.orr.OrrMaterialInterruptSummaryEntity;
import com.yunhai.model.vo.orr.OrrMaterialInterruptSummaryQuery;
import com.yunhai.model.vo.orr.OrrMaterialInterruptSummaryVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrrMaterialInterruptSummaryServiceImpl implements OrrMaterialInterruptSummaryService {

    @Resource
    private OrrMaterialInterruptSummaryMapper orrMaterialInterruptSummaryMapper;

    /**
     * 获取 OrrMaterialInterruptSummary 分页列表
     */
    @Transactional
    public IPage getOrrMaterialInterruptSummaryPagination(PaginationVo paginationVo, OrrMaterialInterruptSummaryQuery orrMaterialInterruptSummaryQuery ) throws Exception {

        IPage page = new Page( paginationVo.getPageIndex(), paginationVo.getPageSize() );
        LambdaQueryWrapper<OrrMaterialInterruptSummaryEntity> lqs = new LambdaQueryWrapper();
        orrMaterialInterruptSummaryMapper.selectPage(page, lqs);

        List<OrrMaterialInterruptSummaryEntity> record = page.getRecords();
        if( !ObjectUtil.isNotEmptyList(record)){
            return page;
        }
        return page;
    }


    /**
     * 获取 OrrMaterialInterruptSummary 所有数据
     *
     */
    @Transactional
    public List<OrrMaterialInterruptSummaryEntity> getOrrMaterialInterruptSummaryAllList( OrrMaterialInterruptSummaryQuery orrMaterialInterruptSummaryQuery ) throws Exception {

        LambdaQueryWrapper<OrrMaterialInterruptSummaryEntity> lqs = new LambdaQueryWrapper();
        List<OrrMaterialInterruptSummaryEntity> list = orrMaterialInterruptSummaryMapper.selectList(lqs);
        return list;
    }


    /**
     * 获取 OrrMaterialInterruptSummary 详情
     */
    @Transactional
    public OrrMaterialInterruptSummaryEntity getOrrMaterialInterruptSummaryDetail( Long id) throws Exception {

        OrrMaterialInterruptSummaryEntity orrMaterialInterruptSummaryEntity = orrMaterialInterruptSummaryMapper.selectById(id);
        return orrMaterialInterruptSummaryEntity;
    }


    /**
     * 新增 OrrMaterialInterruptSummary
     * */
    @Transactional
    public void addOrrMaterialInterruptSummary(OrrMaterialInterruptSummaryVo orrMaterialInterruptSummaryVo) throws Exception {

        OrrMaterialInterruptSummaryEntity orrMaterialInterruptSummaryEntity = new OrrMaterialInterruptSummaryEntity();
        ReflectionCopy.copyProperties( orrMaterialInterruptSummaryEntity, orrMaterialInterruptSummaryVo );
        orrMaterialInterruptSummaryMapper.insert(orrMaterialInterruptSummaryEntity);
        return;
    }


    /**
     * 更新 OrrMaterialInterruptSummary
     * */
    @Transactional
    public void updateOrrMaterialInterruptSummary( OrrMaterialInterruptSummaryVo orrMaterialInterruptSummaryVo) throws Exception {

        if( orrMaterialInterruptSummaryVo.getId() == null ){
            throw GlobalException.gen(10021, "id不存在");
        }
        OrrMaterialInterruptSummaryEntity orrMaterialInterruptSummaryEntity = new OrrMaterialInterruptSummaryEntity();
        ReflectionCopy.copyProperties( orrMaterialInterruptSummaryEntity, orrMaterialInterruptSummaryVo );
        orrMaterialInterruptSummaryMapper.updateById(orrMaterialInterruptSummaryEntity);
        return;
    }

    /**
     * 删除 OrrMaterialInterruptSummary
     * */
    @Transactional
    public void batchRemoveOrrMaterialInterruptSummary( List<Long> ids ) throws Exception {

        if( !ObjectUtil.isNotEmptyList(ids) ){
            throw GlobalException.gen(10011, "要删除的id不存在");
        }
        orrMaterialInterruptSummaryMapper.deleteBatchIds(ids);
    }

}